#ifndef _MESHWIDGET_H_
#define _MESHWIDGET_H_
#include <OgrePrerequisites.h>
#include "OgreWidget.h"

namespace Ogre{ class Rectangle2D; }

class MeshWidget : public OgreWidget
{
  Q_OBJECT

public:
  MeshWidget(QWidget* parent = 0);
  ~MeshWidget(void);

  void loadMesh(QString path);
  void saveMesh(QString path);
  void setBackgroundImage(bool enabled, QString imagePath = QString::null);

signals:
  void animationsChanged(QStringList);

public slots:
  void changeBackgroundColor(QColor);
  void changeAnimation(QString);
  void playAnimation(void);
  void pauseAnimation(void);
  void stopAnimation(void);

protected:
  void initScene(void) override;
  void setupCamera(void) override;
  virtual void update(float timeSinceLastUpdate) override;
  void unloadMesh(void);
  
  // Setup the OgreWidget on the first paintEvent when getDC() returns a
  // valid DS
  void paintEvent(QPaintEvent*);
  virtual void mousePressEvent(QMouseEvent*);
  virtual void mouseMoveEvent(QMouseEvent*);
  virtual void mouseReleaseEvent(QMouseEvent*);
  virtual void keyPressEvent(QKeyEvent*);
  virtual void keyReleaseEvent(QKeyEvent*);
  virtual void wheelEvent(QWheelEvent*);
  virtual void dragEnterEvent(QDragEnterEvent*);
  virtual void dropEvent(QDropEvent*);

private:
  bool loadTexture(QString path);

protected:
  const Ogre::String TEMP_RESOURCE_GROUP;
  Ogre::Entity* mpEntity;
  Ogre::AnimationState* mpAnimation;
  bool mAnimationPaused;
  Ogre::SceneNode* mpYawNode;
  Ogre::SceneNode* mpPitchNode;
  Ogre::SceneNode* mpCamNode;
  Ogre::Rectangle2D* mpBackgroundRect;  // for bg image
  Ogre::Material* mpBackgroundMaterial; // for bg image
};

#endif // _MESHWIDGET_H_